<?php
/**
 * Description: 设置session
 * User: wh
 * Date: 2017-08-29
 * Time: 11:28
 */

namespace app\wxbackend\controller\Wx;
use app\wxbackend\model\Member;

class WxSession
{
    //获取用户的绑定的基础信息
    public static function getMemberBaseInfo($openid)
    {
        $memberModel = new Member();
        $res = $memberModel->getMemberByOpenid($openid);
        return $res ?: false;
    }

    //设置session
    public static function setSession($openid)
    {
        if (!isset($_SESSION) || !$_SESSION) {
            $userInfo = self::getMemberBaseInfo($openid);
            if ($userInfo) {
                //session_id($openid);
                session('openid', $openid);
                session('mid', $userInfo['mid']);
                session('pmid', $userInfo['pmid']);
                session('account', $userInfo['account']);
                session('mobile', $userInfo['mobile']);
                session('status', $userInfo['status']);
                session('dtype', $userInfo['dtype']);
                session('pdtype', $userInfo['pdtype']);
            } else {
                //session_id($openid);
                session('openid', $openid);
                session('mid', '');
                session('pmid', '');
                session('account', '');
                session('mobile', '');
                session('status', '');
                session('dtype', '');
                session('pdtype', '');
            }
        }
    }
}